// 发送短信验证码
const Core = require('@alicloud/pop-core');

var client = new Core({
  accessKeyId: 'LTAI4FrDD7ht2BCDJM8cb4uY', // 自己的id
  accessKeySecret: 'DOeQvVr7dt0tU2d5Zf0h8qNQpTlfc9', // 自己的secret
  endpoint: 'https://dysmsapi.aliyuncs.com',
  apiVersion: '2017-05-25'
});

module.exports =  {
  sendCode (tel, code) {
    
    var params = {
      "RegionId": "cn-hangzhou",
      "PhoneNumbers": tel,
      "SignName": "华药", // 自己的签名
      "TemplateCode": "SMS_177536400", // 自己的模板代码
      "TemplateParam": "{code: " + code + "}"
    }

    var requestOption = {
      method: 'POST'
    };

    return new Promise((resolve, reject) => {
      client.request('SendSms', params, requestOption).then((result) => {
        console.log(JSON.stringify(result));
        resolve(code)
      }, (ex) => {
        console.log(ex);
        reject()
      })
    })
  }
}
